﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using AMPLibrary;
using AMPLibrary.Media;

namespace AMPLibrary.Controls
{
    /// <summary>
    /// Interaction logic for UserMediaRatingControl.xaml
    /// </summary>
    public partial class UserMediaRatingControl : UserControl
    {
        private MediaFile currentMedia;

        public UserMediaRatingControl()
        {
            InitializeComponent();
        }

        public void BindMedia(ref MediaFile currentMedia)
        {
            this.currentMedia = currentMedia;
            BindRating();
        }

        public void ratingRadioButton_OnClick(object sender, RoutedEventArgs e)
        {
            if (this.currentMedia == null)
                return;

            RadioButton rb = (RadioButton)sender;

            if (rb == null)
                return;

            switch (rb.Name)
            {
                case "a":
                    this.currentMedia.UserMediaRating = UserMediaRating.OneStar;
                    break;

                case "b":
                    this.currentMedia.UserMediaRating = UserMediaRating.TwoStars;
                    break;

                case "c":
                    this.currentMedia.UserMediaRating = UserMediaRating.ThreeStars;
                    break;

                case "d":
                    this.currentMedia.UserMediaRating = UserMediaRating.FourStars;
                    break;

                case "e":
                    this.currentMedia.UserMediaRating = UserMediaRating.FiveStars;
                    break;
            }

            BindRating();
        }

        private void BindRating()
        {
            if (this.currentMedia == null)
                return;

            this.a.IsChecked = false;
            this.b.IsChecked = false;
            this.c.IsChecked = false;
            this.d.IsChecked = false;
            this.e.IsChecked = false;

            switch (currentMedia.UserMediaRating)
            {
                case UserMediaRating.OneStar:
                    this.a.IsChecked = true;
                    break;

                case UserMediaRating.TwoStars:
                    this.a.IsChecked = true;
                    this.b.IsChecked = true;
                    break;

                case UserMediaRating.ThreeStars:
                    this.a.IsChecked = true;
                    this.b.IsChecked = true;
                    this.c.IsChecked = true;
                    break;

                case UserMediaRating.FourStars:
                    this.a.IsChecked = true;
                    this.b.IsChecked = true;
                    this.c.IsChecked = true;
                    this.d.IsChecked = true;
                    break;

                case UserMediaRating.FiveStars:
                    this.a.IsChecked = true;
                    this.b.IsChecked = true;
                    this.c.IsChecked = true;
                    this.d.IsChecked = true;
                    this.e.IsChecked = true;
                    break;
            }
        }
    }
}
